Skip to content

Commit

Permalink
cil/config/credentials: remove newStore() test-utility
Browse files Browse the repository at this point in the history
This function was names slightly confusing, as it returns a fakeStore,
and it didn't do any constructing, so didn't provide value above just
constructing the type.

I'm planning to add more functionality to the fakeStore, but don't want
to maintain a full-fledged constructor for all of that, so let's remove
this utility.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Oct 22, 2024
1 parent 0ab0eca commit 0dd6f7f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 27 deletions.
18 changes: 7 additions & 11 deletions cli/config/credentials/file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,8 @@ func (f *fakeStore) GetFilename() string {
return "/tmp/docker-fakestore"
}

func newStore(auths map[string]types.AuthConfig) store {
return &fakeStore{configs: auths}
}

func TestFileStoreAddCredentials(t *testing.T) {
f := newStore(make(map[string]types.AuthConfig))
f := &fakeStore{configs: map[string]types.AuthConfig{}}

s := NewFileStore(f)
auth := types.AuthConfig{
Expand All @@ -47,13 +43,13 @@ func TestFileStoreAddCredentials(t *testing.T) {
}

func TestFileStoreGet(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
"https://example.com": {
Auth: "super_secret_token",
Email: "[email protected]",
ServerAddress: "https://example.com",
},
})
}}

s := NewFileStore(f)
a, err := s.Get("https://example.com")
Expand All @@ -71,7 +67,7 @@ func TestFileStoreGet(t *testing.T) {
func TestFileStoreGetAll(t *testing.T) {
s1 := "https://example.com"
s2 := "https://example2.example.com"
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
s1: {
Auth: "super_secret_token",
Email: "[email protected]",
Expand All @@ -82,7 +78,7 @@ func TestFileStoreGetAll(t *testing.T) {
Email: "[email protected]",
ServerAddress: "https://example2.example.com",
},
})
}}

s := NewFileStore(f)
as, err := s.GetAll()
Expand All @@ -107,13 +103,13 @@ func TestFileStoreGetAll(t *testing.T) {
}

func TestFileStoreErase(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
"https://example.com": {
Auth: "super_secret_token",
Email: "[email protected]",
ServerAddress: "https://example.com",
},
})
}}

s := NewFileStore(f)
err := s.Erase("https://example.com")
Expand Down
32 changes: 16 additions & 16 deletions cli/config/credentials/native_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func mockCommandFn(args ...string) client.Program {
}

func TestNativeStoreAddCredentials(t *testing.T) {
f := newStore(make(map[string]types.AuthConfig))
f := &fakeStore{configs: map[string]types.AuthConfig{}}
s := &nativeStore{
programFunc: mockCommandFn,
fileStore: NewFileStore(f),
Expand All @@ -116,7 +116,7 @@ func TestNativeStoreAddCredentials(t *testing.T) {
}

func TestNativeStoreAddInvalidCredentials(t *testing.T) {
f := newStore(make(map[string]types.AuthConfig))
f := &fakeStore{configs: map[string]types.AuthConfig{}}
s := &nativeStore{
programFunc: mockCommandFn,
fileStore: NewFileStore(f),
Expand All @@ -132,11 +132,11 @@ func TestNativeStoreAddInvalidCredentials(t *testing.T) {
}

func TestNativeStoreGet(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "[email protected]",
},
})
}}
s := &nativeStore{
programFunc: mockCommandFn,
fileStore: NewFileStore(f),
Expand All @@ -154,11 +154,11 @@ func TestNativeStoreGet(t *testing.T) {
}

func TestNativeStoreGetIdentityToken(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress2: {
Email: "[email protected]",
},
})
}}

s := &nativeStore{
programFunc: mockCommandFn,
Expand All @@ -176,11 +176,11 @@ func TestNativeStoreGetIdentityToken(t *testing.T) {
}

func TestNativeStoreGetAll(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "[email protected]",
},
})
}}

s := &nativeStore{
programFunc: mockCommandFn,
Expand Down Expand Up @@ -217,11 +217,11 @@ func TestNativeStoreGetAll(t *testing.T) {
}

func TestNativeStoreGetMissingCredentials(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "[email protected]",
},
})
}}

s := &nativeStore{
programFunc: mockCommandFn,
Expand All @@ -232,11 +232,11 @@ func TestNativeStoreGetMissingCredentials(t *testing.T) {
}

func TestNativeStoreGetInvalidAddress(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "[email protected]",
},
})
}}

s := &nativeStore{
programFunc: mockCommandFn,
Expand All @@ -247,11 +247,11 @@ func TestNativeStoreGetInvalidAddress(t *testing.T) {
}

func TestNativeStoreErase(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "[email protected]",
},
})
}}

s := &nativeStore{
programFunc: mockCommandFn,
Expand All @@ -263,11 +263,11 @@ func TestNativeStoreErase(t *testing.T) {
}

func TestNativeStoreEraseInvalidAddress(t *testing.T) {
f := newStore(map[string]types.AuthConfig{
f := &fakeStore{configs: map[string]types.AuthConfig{
validServerAddress: {
Email: "[email protected]",
},
})
}}

s := &nativeStore{
programFunc: mockCommandFn,
Expand Down

0 comments on commit 0dd6f7f

Please sign in to comment.