This repository has been archived by the owner on Mar 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional testing and fixes from code review
marginally more testing - stateGetter increase coverage of integration test framework code yes I know this is redundant also add that to 'make test' refactor to avoid viper calls at runtime factor out 'fetchEditFiles' function add unit test for app type determination code remove unneeded 'fs.RemoveAll' from stategetter code
- Loading branch information
Showing
11 changed files
with
381 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package apptype | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/replicatedhq/ship/pkg/state" | ||
"github.com/replicatedhq/ship/pkg/testing/logger" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_inspector_fetchEditFiles(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
state state.UpstreamContents | ||
wantApp LocalAppCopy | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "app release contents", | ||
state: state.UpstreamContents{ | ||
AppRelease: &state.ShipRelease{}, | ||
}, | ||
wantApp: &localAppCopy{AppType: "replicated.app"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "k8s yaml contents", | ||
state: state.UpstreamContents{ | ||
UpstreamFiles: []state.UpstreamFile{ | ||
{FilePath: "test.yaml", FileContents: "YTogYg=="}, | ||
}, | ||
}, | ||
wantApp: &localAppCopy{AppType: "k8s"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "helm chart yaml contents", | ||
state: state.UpstreamContents{ | ||
UpstreamFiles: []state.UpstreamFile{ | ||
{FilePath: "test.yaml", FileContents: "YTogYg=="}, | ||
{FilePath: "Chart.yaml", FileContents: "VGhpcyBpcyBwcm9iYWJseSBub3QgYSB2YWxpZCBoZWxtIGNoYXJ0IHlhbWwgZmlsZQ=="}, | ||
}, | ||
}, | ||
wantApp: &localAppCopy{AppType: "helm"}, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "inline replicated app contents", | ||
state: state.UpstreamContents{ | ||
UpstreamFiles: []state.UpstreamFile{ | ||
{FilePath: "test.yaml", FileContents: "YTogYg=="}, | ||
{FilePath: "ship.yaml", FileContents: "SSBBTSBTSElQ"}, | ||
}, | ||
}, | ||
wantApp: &localAppCopy{AppType: "inline.replicated.app"}, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
req := require.New(t) | ||
|
||
fs := afero.Afero{Fs: afero.NewMemMapFs()} | ||
tlog := logger.TestLogger{T: t} | ||
|
||
vip := viper.New() | ||
vip.Set("isEdit", true) | ||
|
||
manager := state.NewManager(&tlog, fs, vip) | ||
err := manager.SerializeUpstreamContents(&tt.state) | ||
req.NoError(err) | ||
|
||
i := NewInspector(&tlog, fs, vip, manager, nil).(*inspector) | ||
|
||
gotApp, err := i.fetchEditFiles(context.Background()) | ||
if tt.wantErr { | ||
req.Error(err) | ||
} else { | ||
req.NoError(err) | ||
} | ||
|
||
req.Equal(tt.wantApp.GetType(), gotApp.GetType()) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.