core/config_test.go
core/config_test.goBrowse 1970 files
800 tokens
2,560 bytes
Token encoding: o200k_base
Snapshot 21a254f
← Back to SKILL.md
1package core2 3import (4 "encoding/json"5 "testing"6 7 "github.com/google/go-cmp/cmp"8 9 "github.com/railwayapp/railpack/core/app"10 "github.com/railwayapp/railpack/core/config"11 "github.com/stretchr/testify/require"12)13 14func TestGenerateConfigFromEnvironment(t *testing.T) {15 tests := []struct {16 name string17 envVars map[string]string18 expected string19 }{20 {21 name: "empty environment",22 envVars: map[string]string{},23 expected: `{24 "steps": {},25 "packages": {},26 "caches": {},27 "deploy": {}28 }`,29 },30 31 {32 name: "kitchen sink",33 envVars: map[string]string{34 "RAILPACK_INSTALL_CMD": "npm install",35 "RAILPACK_BUILD_CMD": "npm run build",36 "RAILPACK_START_CMD": "npm start",37 "RAILPACK_PACKAGES": "node@18 python@3.9",38 "RAILPACK_BUILD_APT_PACKAGES": "build-essential libssl-dev",39 "RAILPACK_DEPLOY_APT_PACKAGES": "libssl-dev",40 },41 expected: `{42 "steps": {43 "install": {44 "name": "install",45 "commands": [46 { "src": ".", "dest": "." },47 "npm install"48 ],49 "secrets": ["*"],50 "assets": {},51 "variables": {}52 },53 "build": {54 "name": "build",55 "commands": [56 { "src": ".", "dest": "." },57 "npm run build"58 ],59 "secrets": ["*"],60 "assets": {},61 "variables": {}62 }63 },64 "buildAptPackages": ["build-essential", "libssl-dev"],65 "packages": {66 "node": "18",67 "python": "3.9"68 },69 "caches": {},70 "deploy": {71 "startCommand": "npm start",72 "aptPackages": ["libssl-dev"]73 },74 "secrets": ["RAILPACK_BUILD_APT_PACKAGES", "RAILPACK_BUILD_CMD", "RAILPACK_DEPLOY_APT_PACKAGES",75 "RAILPACK_INSTALL_CMD", "RAILPACK_PACKAGES", "RAILPACK_START_CMD"]76 }`,77 },78 79 {80 name: "unversioned packages",81 envVars: map[string]string{82 "RAILPACK_PACKAGES": "jq pipx:httpie@3.2.4",83 },84 expected: `{85 "steps": {},86 "packages": {87 "jq": "latest",88 "pipx:httpie": "3.2.4"89 },90 "caches": {},91 "deploy": {},92 "secrets": ["RAILPACK_PACKAGES"]93 }`,94 },95 }96 97 for _, tt := range tests {98 t.Run(tt.name, func(t *testing.T) {99 env := app.NewEnvironment(&tt.envVars)100 gotConfig := GenerateConfigFromEnvironment(env)101 102 serializedConfig := config.Config{}103 err := json.Unmarshal([]byte(tt.expected), &serializedConfig)104 require.NoError(t, err)105 106 if diff := cmp.Diff(serializedConfig, *gotConfig); diff != "" {107 t.Errorf("GenerateConfigFromEnvironment() mismatch (-want +got):\n%s", diff)108 }109 })110 }111}112