cli/common_test.go
cli/common_test.goBrowse 1970 files
485 tokens
1,777 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package cli2 3import (4 "encoding/json"5 "fmt"6 "testing"7 8 "github.com/railwayapp/railpack/core/config"9 "github.com/railwayapp/railpack/core/mise"10 "github.com/railwayapp/railpack/core/plan"11 "github.com/stretchr/testify/require"12)13 14func TestAddSchemaToPlanMap_IncludesSchemaAndPreservesPlan(t *testing.T) {15 // Create a minimal non-empty plan16 p := plan.NewBuildPlan()17 p.Deploy.StartCmd = "run"18 p.Secrets = []string{"FOO"}19 20 // Marshal the original plan to a map for comparison21 baseBytes, err := json.Marshal(p)22 require.NoError(t, err)23 var baseMap map[string]any24 require.NoError(t, json.Unmarshal(baseBytes, &baseMap))25 26 // Get the map with schema and validate27 outMap, err := addSchemaToPlanMap(p)28 require.NoError(t, err)29 require.Equal(t, config.SchemaUrl, outMap["$schema"])30 31 // Remove the added $schema and compare with the original32 delete(outMap, "$schema")33 require.Equal(t, baseMap, outMap)34}35 36func TestExitCodeForError(t *testing.T) {37 temporary := &mise.TemporaryError{URL: "https://example.com/mise.tar.gz", Err: fmt.Errorf("i/o timeout")}38 39 tests := []struct {40 name string41 err error42 expected int43 }{44 {name: "temporary", err: temporary, expected: ExitCodeTransient},45 {name: "wrapped temporary", err: fmt.Errorf("failed to ensure mise is installed: %w", temporary), expected: ExitCodeTransient},46 {name: "deterministic", err: fmt.Errorf("no start command was found"), expected: ExitCodeFailure},47 }48 49 for _, tt := range tests {50 t.Run(tt.name, func(t *testing.T) {51 require.Equal(t, tt.expected, exitCodeForError(tt.err))52 })53 }54}55 56func TestAddSchemaToPlanMap_NilPlan(t *testing.T) {57 outMap, err := addSchemaToPlanMap(nil)58 require.NoError(t, err)59 require.Len(t, outMap, 1)60 require.Equal(t, config.SchemaUrl, outMap["$schema"])61}62