github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/acceptance/adapter_test.go (about) 1 // Copyright 2017 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package acceptance 12 13 import ( 14 "context" 15 "strings" 16 "testing" 17 18 "github.com/cockroachdb/cockroach/pkg/util/log" 19 ) 20 21 func TestDockerC(t *testing.T) { 22 s := log.Scope(t) 23 defer s.Close(t) 24 25 ctx := context.Background() 26 t.Run("Success", func(t *testing.T) { 27 testDockerSuccess(ctx, t, "c", []string{ 28 "sh", "-c", 29 `cd /mnt/data/c && make test && ./test 'SELECT $1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12'`, 30 }) 31 }) 32 t.Run("Fail", func(t *testing.T) { 33 testDockerFail(ctx, t, "c", []string{ 34 "sh", "-c", 35 `cd /mnt/data/c && make test && ./test 'SELECT 1'`, 36 }) 37 }) 38 } 39 40 func TestDockerCSharp(t *testing.T) { 41 s := log.Scope(t) 42 defer s.Close(t) 43 44 ctx := context.Background() 45 testDockerSuccess(ctx, t, "csharp", []string{"sh", "-c", "cd /mnt/data/csharp && dotnet run"}) 46 testDockerFail(ctx, t, "csharp", []string{"sh", "-c", "cd /mnt/data/csharp && dotnet notacommand"}) 47 } 48 49 func TestDockerJava(t *testing.T) { 50 s := log.Scope(t) 51 defer s.Close(t) 52 53 ctx := context.Background() 54 testDockerSuccess(ctx, t, "java", []string{"sh", "-c", "cd /mnt/data/java && mvn -o test"}) 55 testDockerFail(ctx, t, "java", []string{"sh", "-c", "cd /mnt/data/java && mvn -o foobar"}) 56 } 57 58 func TestDockerElixir(t *testing.T) { 59 s := log.Scope(t) 60 defer s.Close(t) 61 62 ctx := context.Background() 63 testDockerSuccess(ctx, t, "elixir", []string{"sh", "-c", "cd /mnt/data/elixir/test_crdb && mix local.hex --force && mix deps.get && psql -c 'CREATE DATABASE IF NOT EXISTS testdb' && mix test"}) 64 testDockerFail(ctx, t, "elixir", []string{"sh", "-c", "cd /mnt/data/elixir/test_crdb && mix local.hex --force && mix deps.get && mix thisshouldfail"}) 65 } 66 67 func TestDockerNodeJS(t *testing.T) { 68 s := log.Scope(t) 69 defer s.Close(t) 70 71 const nodeJS = ` 72 set -e 73 cd /mnt/data/node 74 75 export SHOULD_FAIL=%v 76 # Get access to globally installed node modules. 77 export NODE_PATH=$NODE_PATH:/usr/lib/node 78 /usr/lib/node/.bin/mocha . 79 ` 80 81 ctx := context.Background() 82 testDockerSuccess(ctx, t, "node.js", []string{"/bin/sh", "-c", strings.Replace(nodeJS, "%v", "", 1)}) 83 testDockerFail(ctx, t, "node.js", []string{"/bin/sh", "-c", strings.Replace(nodeJS, "%v", "fail", 1)}) 84 } 85 86 func TestDockerPHP(t *testing.T) { 87 s := log.Scope(t) 88 defer s.Close(t) 89 90 ctx := context.Background() 91 testDockerSuccess(ctx, t, "php", []string{"sh", "-c", "cd /mnt/data/php && php test.php 3"}) 92 testDockerFail(ctx, t, "php", []string{"sh", "-c", "cd /mnt/data/php && php test.php 1"}) 93 } 94 95 func TestDockerPSQL(t *testing.T) { 96 s := log.Scope(t) 97 defer s.Close(t) 98 99 ctx := context.Background() 100 testDockerSuccess(ctx, t, "psql", []string{"/mnt/data/psql/test-psql.sh"}) 101 } 102 103 func TestDockerPython(t *testing.T) { 104 s := log.Scope(t) 105 defer s.Close(t) 106 107 ctx := context.Background() 108 testDockerSuccess(ctx, t, "python", []string{"sh", "-c", "cd /mnt/data/python && python test.py 3"}) 109 testDockerFail(ctx, t, "python", []string{"sh", "-c", "cd /mnt/data/python && python test.py 2"}) 110 } 111 112 func TestDockerRuby(t *testing.T) { 113 s := log.Scope(t) 114 defer s.Close(t) 115 116 ctx := context.Background() 117 testDockerSuccess(ctx, t, "ruby", []string{"sh", "-c", "cd /mnt/data/ruby && ruby test.rb 3"}) 118 testDockerFail(ctx, t, "ruby", []string{"sh", "-c", "cd /mnt/data/ruby && ruby test.rb 1"}) 119 }