Skip to content

Commit

Permalink
Delete original integration test scaffolding
Browse files Browse the repository at this point in the history
  • Loading branch information
divolgin committed Jan 25, 2025
1 parent e6a7008 commit cd266aa
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 115 deletions.
7 changes: 0 additions & 7 deletions cli/cmd/app_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/replicatedhq/replicated/pkg/integration"
"github.com/replicatedhq/replicated/pkg/kotsclient"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -40,12 +39,6 @@ replicated app create "Custom App" --output table`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
if integrationTest != "" {
ctx = context.WithValue(ctx, integration.IntegrationTestContextKey, integrationTest)
}
if logAPICalls != "" {
ctx = context.WithValue(ctx, integration.APICallLogContextKey, logAPICalls)
}

if len(args) != 1 {
return errors.New("missing app name")
Expand Down
8 changes: 0 additions & 8 deletions cli/cmd/app_ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/replicatedhq/replicated/pkg/integration"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -40,13 +39,6 @@ replicated app ls --output json
replicated app ls "App Name" --output table`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
if integrationTest != "" {
ctx = context.WithValue(ctx, integration.IntegrationTestContextKey, integrationTest)
}
if logAPICalls != "" {
ctx = context.WithValue(ctx, integration.APICallLogContextKey, logAPICalls)
}

return r.listApps(ctx, cmd, args, outputFormat)
},
SilenceUsage: true,
Expand Down
8 changes: 0 additions & 8 deletions cli/cmd/app_rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/manifoldco/promptui"
"github.com/pkg/errors"
"github.com/replicatedhq/replicated/cli/print"
"github.com/replicatedhq/replicated/pkg/integration"
"github.com/replicatedhq/replicated/pkg/logger"
"github.com/replicatedhq/replicated/pkg/types"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -40,13 +39,6 @@ replicated app delete "Another App" --force
replicated app delete "Custom App" --output json`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
if integrationTest != "" {
ctx = context.WithValue(ctx, integration.IntegrationTestContextKey, integrationTest)
}
if logAPICalls != "" {
ctx = context.WithValue(ctx, integration.APICallLogContextKey, logAPICalls)
}

if len(args) != 1 {
return errors.New("missing app slug or id")
}
Expand Down
8 changes: 0 additions & 8 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ const (

var appSlugOrID string
var apiToken string
var integrationTest string
var logAPICalls string
var platformOrigin = "https://api.replicated.com/vendor"
var kurlDotSHOrigin = "https://kurl.sh"
var cache *replicatedcache.Cache
Expand Down Expand Up @@ -59,12 +57,6 @@ func GetRootCmd() *cobra.Command {
rootCmd.PersistentFlags().StringVar(&appSlugOrID, "app", "", "The app slug or app id to use in all calls")
rootCmd.PersistentFlags().StringVar(&apiToken, "token", "", "The API token to use to access your app in the Vendor API")

rootCmd.PersistentFlags().StringVar(&integrationTest, "integration-test", "", "Set to the name of the integration test to run")
rootCmd.Flags().MarkHidden("integration-test")

rootCmd.PersistentFlags().StringVar(&logAPICalls, "log-api-calls", "", "Log the API calls to the specified file")
rootCmd.Flags().MarkHidden("log-api-calls")

return rootCmd
}

Expand Down
45 changes: 0 additions & 45 deletions pkg/integration/integration.go
Original file line number Diff line number Diff line change
@@ -1,61 +1,16 @@
package integration

import (
"fmt"
"path"

kotsclienttypes "github.com/replicatedhq/replicated/pkg/kotsclient/types"
"github.com/replicatedhq/replicated/pkg/types"
)

type contextKey string

const IntegrationTestContextKey contextKey = "integration-test"
const APICallLogContextKey contextKey = "api-call-log"

type format string

const (
FormatJSON format = "json"
FormatTable format = "table"
)

var (
typeKOTSAppWithChannels = types.KotsAppWithChannels{
Channels: []types.Channel{
{
ID: "channel-id",
Name: "channel-name",
},
},
Id: "id",
Slug: "slug",
Name: "name",
IsFoundation: true,
}
)

func Response(key string) interface{} {
switch key {
case "app-ls-empty":
return &kotsclienttypes.KotsAppResponse{
Apps: []types.KotsAppWithChannels{},
}
case "app-ls-single", "app-rm":
return &kotsclienttypes.KotsAppResponse{
Apps: []types.KotsAppWithChannels{
typeKOTSAppWithChannels,
},
}
case "app-create":
return &kotsclienttypes.CreateKOTSAppResponse{
App: &typeKOTSAppWithChannels,
}
default:
panic(fmt.Sprintf("unknown integration test: %s", key))
}
}

func CLIPath() string {
return path.Join("..", "..", "bin", "replicated")
}
4 changes: 2 additions & 2 deletions pkg/integration/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ func getCommand(cliArgs []string, server *httptest.Server) *exec.Cmd {
cmd := exec.Command(CLIPath(), cliArgs...)
cmd.Env = append(cmd.Env, "REPLICATED_API_ORIGIN="+server.URL)
cmd.Env = append(cmd.Env, "REPLICATED_API_TOKEN=test-token")
cmd.Env = append(cmd.Env, "CI="+os.Getenv("CI")) // disable update checks
cmd.Env = append(cmd.Env, "CI=true") // disable update checks
cmd.Env = append(cmd.Env, "HOME="+os.TempDir())
return cmd
}

func getCommandWithoutToken(cliArgs []string, server *httptest.Server) *exec.Cmd {
cmd := exec.Command(CLIPath(), cliArgs...)
cmd.Env = append(cmd.Env, "REPLICATED_API_ORIGIN="+server.URL)
cmd.Env = append(cmd.Env, "CI="+os.Getenv("CI")) // disable update checks
cmd.Env = append(cmd.Env, "CI=true") // disable update checks
cmd.Env = append(cmd.Env, "HOME="+os.TempDir())
return cmd
}
Expand Down
37 changes: 0 additions & 37 deletions pkg/platformclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"

"github.com/pkg/errors"
"github.com/replicatedhq/replicated/pkg/integration"
"github.com/replicatedhq/replicated/pkg/version"
)

Expand Down Expand Up @@ -104,42 +103,6 @@ func (c *HTTPClient) DoJSONWithoutUnmarshal(method string, path string, reqBody

// DoJSON makes the request, and respBody is a pointer to the struct that we should unmarshal the response into
func (c *HTTPClient) DoJSON(ctx context.Context, method string, path string, successStatus int, reqBody interface{}, respBody interface{}) error {
if ctx.Value(integration.APICallLogContextKey) != nil {
// Log the API call to the file specified in the context
logFile := ctx.Value(integration.APICallLogContextKey).(string)
apiCall := fmt.Sprintf("%s:%s", method, path)

// create the file if it doesn't exist
if _, err := os.Stat(logFile); os.IsNotExist(err) {
if _, err := os.Create(logFile); err != nil {
return fmt.Errorf("failed to create log file: %w", err)
}
}

f, err := os.OpenFile(logFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return fmt.Errorf("failed to open log file: %w", err)
}

if _, err := f.WriteString(apiCall + "\n"); err != nil {
return fmt.Errorf("failed to write to log file: %w", err)
}
}
if ctx.Value(integration.IntegrationTestContextKey) != nil {
if respBody != nil {
testResponse := integration.Response(ctx.Value(integration.IntegrationTestContextKey).(string))
encoded, err := json.Marshal(testResponse)
if err != nil {
return err
}
if err := json.NewDecoder(bytes.NewReader(encoded)).Decode(respBody); err != nil {
return err
}
}

return nil
}

endpoint := fmt.Sprintf("%s%s", c.apiOrigin, path)
var buf bytes.Buffer
if reqBody != nil {
Expand Down

0 comments on commit cd266aa

Please sign in to comment.