Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Windows #401

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
go-version: ['1.20', '1.21']
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
97 changes: 97 additions & 0 deletions internal/config/config_linux_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package config_test

import (
"testing"

"github.com/spf13/afero"

"github.com/gphotosuploader/gphotos-uploader-cli/internal/config"
)

func TestCreate(t *testing.T) {
testCases := []struct {
name string
preCreate string
path string
isErrExpected bool
}{
{"Should success", "", "/home/foo/SourceFolder.hjson", false},
{"Should success w/ existing dir", "/home/bar/SourceFolder.hjson", "/home/bar/SourceFolder.hjson", false},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fs := afero.NewMemMapFs()
createTestConfigurationFile(t, fs, tc.preCreate)

_, err := config.Create(fs, tc.path)
assertExpectedError(t, tc.isErrExpected, err)

if !tc.isErrExpected {
assertFileExistence(t, fs, tc.path)
}
})
}
}

func TestExists(t *testing.T) {
testCases := []struct {
name string
path string
want bool
}{
{"Should return true if exist", "testdata/valid-config/config.hjson", true},
{"Should return false if not exist", "testdata/non-existent/config.hjson", false},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fs := afero.OsFs{}
got := config.Exists(fs, tc.path)
if tc.want != got {
t.Errorf("configuration file does not exist, path: %s", tc.path)
}
})
}
}

func TestFromFile(t *testing.T) {
testCases := []struct {
name string
path string
want string
isErrExpected bool
}{
{"Should success with Album's name option", "testdata/valid-config/configWithAlbumNameOption.hjson", "[email protected]", false},
{"Should success with Album's auto folderName option", "testdata/valid-config/configWithAlbumAutoFolderNameOption.hjson", "[email protected]", false},
{"Should success with Album's auto folderPath option", "testdata/valid-config/configWithAlbumAutoFolderPathOption.hjson", "[email protected]", false},
{"Should success with deprecated CreateAlbums option", "testdata/valid-config/configWithDeprecatedCreateAlbumsOption.hjson", "[email protected]", false},

{"Should fail if config dir does not exist", "testdata/non-existent/config.hjson", "", true},
{"Should fail if Account is invalid", "testdata/invalid-config/EmptyAccount.hjson", "", true},
{"Should fail if SourceFolder does not exist", "testdata/invalid-config/NonExistentSourceFolder.hjson", "", true},
{"Should fail if SecretsBackendType is invalid", "testdata/invalid-config/BadSecretsBackendType.hjson", "", true},
{"Should fail if AppAPICredentials are invalid", "testdata/invalid-config/EmptyAppAPICredentials.hjson", "", true},
{"Should fail if Jobs is empty", "testdata/invalid-config/NoJobs.hjson", "", true},
{"Should fail if Album's format is invalid", "testdata/invalid-config/AlbumBadFormat.hjson", "", true},
{"Should fail if Album's key is invalid", "testdata/invalid-config/AlbumBadKey.hjson", "", true},
{"Should fail if Album's name is invalid", "testdata/invalid-config/AlbumEmptyName.hjson", "", true},
{"Should fail if Album's auto value is invalid", "testdata/invalid-config/AlbumBadAutoValue.hjson", "", true},
{"Should fail if deprecated CreateAlbums is invalid", "testdata/invalid-config/DeprecatedCreateAlbums.hjson", "", true},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fs := afero.OsFs{}
got, err := config.FromFile(fs, tc.path)
if err != nil {
t.Log(err)
}
assertExpectedError(t, tc.isErrExpected, err)

if !tc.isErrExpected && (got.Account != tc.want) {
t.Errorf("want: %s, got: %s", tc.want, got.Account)
}
})
}
}
88 changes: 0 additions & 88 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,94 +9,6 @@ import (
"github.com/gphotosuploader/gphotos-uploader-cli/internal/config"
)

func TestCreate(t *testing.T) {
testCases := []struct {
name string
preCreate string
path string
isErrExpected bool
}{
{"Should success", "", "/home/foo/SourceFolder.hjson", false},
{"Should success w/ existing dir", "/home/bar/SourceFolder.hjson", "/home/bar/SourceFolder.hjson", false},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fs := afero.NewMemMapFs()
createTestConfigurationFile(t, fs, tc.preCreate)

_, err := config.Create(fs, tc.path)
assertExpectedError(t, tc.isErrExpected, err)

if !tc.isErrExpected {
assertFileExistence(t, fs, tc.path)
}
})
}
}

func TestExists(t *testing.T) {
testCases := []struct {
name string
path string
want bool
}{
{"Should return true if exist", "testdata/valid-config/config.hjson", true},
{"Should return false if not exist", "testdata/non-existent/config.hjson", false},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fs := afero.OsFs{}
got := config.Exists(fs, tc.path)
if tc.want != got {
t.Errorf("configuration file does not exist, path: %s", tc.path)
}
})
}
}

func TestFromFile(t *testing.T) {
testCases := []struct {
name string
path string
want string
isErrExpected bool
}{
{"Should success with Album's name option", "testdata/valid-config/configWithAlbumNameOption.hjson", "[email protected]", false},
{"Should success with Album's auto folderName option", "testdata/valid-config/configWithAlbumAutoFolderNameOption.hjson", "[email protected]", false},
{"Should success with Album's auto folderPath option", "testdata/valid-config/configWithAlbumAutoFolderPathOption.hjson", "[email protected]", false},
{"Should success with deprecated CreateAlbums option", "testdata/valid-config/configWithDeprecatedCreateAlbumsOption.hjson", "[email protected]", false},

{"Should fail if config dir does not exist", "testdata/non-existent/config.hjson", "", true},
{"Should fail if Account is invalid", "testdata/invalid-config/EmptyAccount.hjson", "", true},
{"Should fail if SourceFolder does not exist", "testdata/invalid-config/NonExistentSourceFolder.hjson", "", true},
{"Should fail if SecretsBackendType is invalid", "testdata/invalid-config/BadSecretsBackendType.hjson", "", true},
{"Should fail if AppAPICredentials are invalid", "testdata/invalid-config/EmptyAppAPICredentials.hjson", "", true},
{"Should fail if Jobs is empty", "testdata/invalid-config/NoJobs.hjson", "", true},
{"Should fail if Album's format is invalid", "testdata/invalid-config/AlbumBadFormat.hjson", "", true},
{"Should fail if Album's key is invalid", "testdata/invalid-config/AlbumBadKey.hjson", "", true},
{"Should fail if Album's name is invalid", "testdata/invalid-config/AlbumEmptyName.hjson", "", true},
{"Should fail if Album's auto value is invalid", "testdata/invalid-config/AlbumBadAutoValue.hjson", "", true},
{"Should fail if deprecated CreateAlbums is invalid", "testdata/invalid-config/DeprecatedCreateAlbums.hjson", "", true},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
fs := afero.OsFs{}
got, err := config.FromFile(fs, tc.path)
if err != nil {
t.Log(err)
}
assertExpectedError(t, tc.isErrExpected, err)

if !tc.isErrExpected && (got.Account != tc.want) {
t.Errorf("want: %s, got: %s", tc.want, got.Account)
}
})
}
}

func TestConfig_SafePrint(t *testing.T) {
cfg := config.Config{
APIAppCredentials: config.APIAppCredentials{
Expand Down
9 changes: 9 additions & 0 deletions internal/config/config_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package config_test

import (
"testing"
)

func TestCreate(t *testing.T) {
t.Error("Was executed")
}