Browse Source

Fusion program & function tests

pull/768/head
xpetit 4 years ago
parent
commit
01f3d066ca
No known key found for this signature in database
GPG Key ID: 97C60669182C17A5
  1. 88
      go/examples/call-graphql.go
  2. 9
      go/tests/Dockerfile
  3. 2
      go/tests/entrypoint.sh
  4. 0
      go/tests/prog/abort_test/main.go
  5. 0
      go/tests/prog/activebits_test/main.go
  6. 0
      go/tests/prog/advancedsortwordarr_test/main.go
  7. 0
      go/tests/prog/alphacount_test/main.go
  8. 0
      go/tests/prog/any_test/main.go
  9. 0
      go/tests/prog/appendrange_test/main.go
  10. 0
      go/tests/prog/atoi_test/main.go
  11. 0
      go/tests/prog/atoibase_test/main.go
  12. 0
      go/tests/prog/basicatoi2_test/main.go
  13. 0
      go/tests/prog/basicatoi_test/main.go
  14. 0
      go/tests/prog/basicjoin_test/main.go
  15. 0
      go/tests/prog/btreeapplybylevel_test/main.go
  16. 0
      go/tests/prog/btreeapplyinorder_test/main.go
  17. 0
      go/tests/prog/btreeapplypostorder_test/main.go
  18. 0
      go/tests/prog/btreeapplypreorder_test/main.go
  19. 0
      go/tests/prog/btreedeletenode_test/main.go
  20. 0
      go/tests/prog/btreeinsertdata_test/main.go
  21. 0
      go/tests/prog/btreeisbinary_test/main.go
  22. 0
      go/tests/prog/btreelevelcount_test/main.go
  23. 0
      go/tests/prog/btreemax_test/main.go
  24. 0
      go/tests/prog/btreemin_test/main.go
  25. 0
      go/tests/prog/btreesearchitem_test/main.go
  26. 0
      go/tests/prog/btreetransplant_test/main.go
  27. 0
      go/tests/prog/capitalize_test/main.go
  28. 0
      go/tests/prog/chunk_test/main.go
  29. 0
      go/tests/prog/collatzcountdown_test/main.go
  30. 0
      go/tests/prog/compact_test/main.go
  31. 0
      go/tests/prog/compare_test/main.go
  32. 0
      go/tests/prog/concat_test/main.go
  33. 0
      go/tests/prog/concatparams_test/main.go
  34. 0
      go/tests/prog/convertbase_test/main.go
  35. 0
      go/tests/prog/correct/btree.go
  36. 0
      go/tests/prog/correct/challenge.go
  37. 0
      go/tests/prog/correct/listat.go
  38. 0
      go/tests/prog/correct/listclear.go
  39. 0
      go/tests/prog/correct/listfind.go
  40. 0
      go/tests/prog/correct/listforeach.go
  41. 0
      go/tests/prog/correct/listforeachif.go
  42. 0
      go/tests/prog/correct/listlast.go
  43. 0
      go/tests/prog/correct/listmerge.go
  44. 0
      go/tests/prog/correct/listpushback.go
  45. 0
      go/tests/prog/correct/listpushfront.go
  46. 0
      go/tests/prog/correct/listremoveif.go
  47. 0
      go/tests/prog/correct/listreverse.go
  48. 0
      go/tests/prog/correct/listsize.go
  49. 0
      go/tests/prog/correct/listsort.go
  50. 0
      go/tests/prog/correct/sortedlistmerge.go
  51. 0
      go/tests/prog/correct/sortlistinsert.go
  52. 0
      go/tests/prog/countif_test/main.go
  53. 0
      go/tests/prog/divmod_test/main.go
  54. 0
      go/tests/prog/doppelganger_test/main.go
  55. 0
      go/tests/prog/eightqueens_test/main.go
  56. 0
      go/tests/prog/enigma_test/main.go
  57. 0
      go/tests/prog/fib_test/main.go
  58. 0
      go/tests/prog/fibonacci_test/main.go
  59. 0
      go/tests/prog/findnextprime_test/main.go
  60. 0
      go/tests/prog/findprevprime_test/main.go
  61. 0
      go/tests/prog/firstrune_test/main.go
  62. 0
      go/tests/prog/foldint_test/main.go
  63. 0
      go/tests/prog/foreach_test/main.go
  64. 0
      go/tests/prog/game23_test/main.go
  65. 0
      go/tests/prog/halfcontest_test/main.go
  66. 0
      go/tests/prog/index_test/main.go
  67. 0
      go/tests/prog/interestingnumber_test/main.go
  68. 0
      go/tests/prog/isalpha_test/main.go
  69. 0
      go/tests/prog/isanagram_test/main.go
  70. 0
      go/tests/prog/islower_test/main.go
  71. 0
      go/tests/prog/isnegative_test/main.go
  72. 0
      go/tests/prog/isnumeric_test/main.go
  73. 0
      go/tests/prog/isprime_test/main.go
  74. 0
      go/tests/prog/isprintable_test/main.go
  75. 0
      go/tests/prog/issorted_test/main.go
  76. 0
      go/tests/prog/isupper_test/main.go
  77. 0
      go/tests/prog/iterativefactorial_test/main.go
  78. 0
      go/tests/prog/iterativepower_test/main.go
  79. 0
      go/tests/prog/itoa_test/main.go
  80. 0
      go/tests/prog/itoabase_test/main.go
  81. 0
      go/tests/prog/join_test/main.go
  82. 0
      go/tests/prog/lastrune_test/main.go
  83. 0
      go/tests/prog/lcm_test/main.go
  84. 0
      go/tests/prog/listat_test/main.go
  85. 0
      go/tests/prog/listclear_test/main.go
  86. 0
      go/tests/prog/listfind_test/main.go
  87. 0
      go/tests/prog/listforeach_test/main.go
  88. 0
      go/tests/prog/listforeachif_test/main.go
  89. 0
      go/tests/prog/listlast_test/main.go
  90. 0
      go/tests/prog/listmerge_test/main.go
  91. 0
      go/tests/prog/listpushback_test/main.go
  92. 0
      go/tests/prog/listpushfront_test/main.go
  93. 0
      go/tests/prog/listremoveif_test/main.go
  94. 0
      go/tests/prog/listreverse_test/main.go
  95. 0
      go/tests/prog/listsize_test/main.go
  96. 0
      go/tests/prog/listsort_test/main.go
  97. 0
      go/tests/prog/makerange_test/main.go
  98. 0
      go/tests/prog/map_test/main.go
  99. 0
      go/tests/prog/max_test/main.go
  100. 0
      go/tests/prog/nauuo_test/main.go
  101. Some files were not shown because too many files changed in this diff diff.show_more

88
go/examples/call-graphql.go

@ -1,88 +0,0 @@
package main
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"os"
)
func jsonPrettyPrint(in []byte) string {
var out bytes.Buffer
err := json.Indent(&out, in, "", " ")
if err != nil {
return string(in)
}
return out.String()
}
var HASURA_GRAPHQL_ADDRESS = os.Getenv("HASURA_GRAPHQL_ADDRESS")
var HASURA_GRAPHQL_ADMIN_SECRET = os.Getenv("HASURA_GRAPHQL_ADMIN_SECRET")
type GraphqlQuery struct {
Data interface{}
}
var client = &http.Client{Transport: http.DefaultTransport}
func hasura(query string, variables interface{}, data interface{}) (err error) {
variablesBytes, err := json.Marshal(variables)
if err != nil {
return
}
v := string(variablesBytes)
requestBody := []byte(`{"query":"` + query + `","variables":` + v + `}`)
requestBytes := bytes.NewBuffer(requestBody)
req, err := http.NewRequest("POST", HASURA_GRAPHQL_ADDRESS, requestBytes)
if err != nil {
return
}
req.Header.Add("X-Hasura-Admin-Secret", HASURA_GRAPHQL_ADMIN_SECRET)
resp, err := client.Do(req)
if err != nil {
return
}
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
// loggin the answer for debugging purposes
fmt.Println(jsonPrettyPrint(b))
if resp.StatusCode < 200 || resp.StatusCode > 299 {
return errors.New(http.StatusText(resp.StatusCode))
}
return json.Unmarshal(b, &GraphqlQuery{Data: data})
}
type User struct {
GithubLogin string
}
const userQuery = `
query {
user {
githubLogin
}
}`
func getUsers() (users []User, err error) {
var data map[string][]User
err = hasura(userQuery, nil, &data)
return data["user"], err
}
func main() {
fmt.Println(getUsers())
}
// HASURA_GRAPHQL_ADMIN_SECRET=VERYVERYSECRET HASURA_GRAPHQL_ADDRESS=http://localhost/graphql-engine/v1alpha1/graphql go run call-graphql.go

9
go/tests/Dockerfile

@ -5,17 +5,18 @@ RUN apk add --no-cache git
RUN go get golang.org/x/tools/cmd/goimports
RUN mkdir -p /piscine-go
RUN touch /piscine-go/go.mod
WORKDIR /piscine-go
RUN go mod init piscine-go
RUN go get github.com/01-edu/z01@v0.1.0
WORKDIR /public/go/tests
COPY go.* ./
RUN go mod download
COPY func func
COPY lib lib
COPY prog prog
RUN go get github.com/01-edu/rc
RUN go install ./prog/...
RUN go install $(grep -rl ChallengeMain ./prog | rev | cut -d/ -f2- | rev)
RUN rm -rf /piscine-go
COPY entrypoint.sh /usr/local/bin

2
go/tests/entrypoint.sh

@ -52,5 +52,5 @@ if command -v "${EXERCISE}_test" >/dev/null 2>&1; then
"${EXERCISE}_test"
else
# The exercise is a function
go run "./func/${EXERCISE}_test"
go run "./prog/${EXERCISE}_test"
fi

0
go/tests/func/abort_test/main.go → go/tests/prog/abort_test/main.go

0
go/tests/func/activebits_test/main.go → go/tests/prog/activebits_test/main.go

0
go/tests/func/advancedsortwordarr_test/main.go → go/tests/prog/advancedsortwordarr_test/main.go

0
go/tests/func/alphacount_test/main.go → go/tests/prog/alphacount_test/main.go

0
go/tests/func/any_test/main.go → go/tests/prog/any_test/main.go

0
go/tests/func/appendrange_test/main.go → go/tests/prog/appendrange_test/main.go

0
go/tests/func/atoi_test/main.go → go/tests/prog/atoi_test/main.go

0
go/tests/func/atoibase_test/main.go → go/tests/prog/atoibase_test/main.go

0
go/tests/func/basicatoi2_test/main.go → go/tests/prog/basicatoi2_test/main.go

0
go/tests/func/basicatoi_test/main.go → go/tests/prog/basicatoi_test/main.go

0
go/tests/func/basicjoin_test/main.go → go/tests/prog/basicjoin_test/main.go

0
go/tests/func/btreeapplybylevel_test/main.go → go/tests/prog/btreeapplybylevel_test/main.go

0
go/tests/func/btreeapplyinorder_test/main.go → go/tests/prog/btreeapplyinorder_test/main.go

0
go/tests/func/btreeapplypostorder_test/main.go → go/tests/prog/btreeapplypostorder_test/main.go

0
go/tests/func/btreeapplypreorder_test/main.go → go/tests/prog/btreeapplypreorder_test/main.go

0
go/tests/func/btreedeletenode_test/main.go → go/tests/prog/btreedeletenode_test/main.go

0
go/tests/func/btreeinsertdata_test/main.go → go/tests/prog/btreeinsertdata_test/main.go

0
go/tests/func/btreeisbinary_test/main.go → go/tests/prog/btreeisbinary_test/main.go

0
go/tests/func/btreelevelcount_test/main.go → go/tests/prog/btreelevelcount_test/main.go

0
go/tests/func/btreemax_test/main.go → go/tests/prog/btreemax_test/main.go

0
go/tests/func/btreemin_test/main.go → go/tests/prog/btreemin_test/main.go

0
go/tests/func/btreesearchitem_test/main.go → go/tests/prog/btreesearchitem_test/main.go

0
go/tests/func/btreetransplant_test/main.go → go/tests/prog/btreetransplant_test/main.go

0
go/tests/func/capitalize_test/main.go → go/tests/prog/capitalize_test/main.go

0
go/tests/func/chunk_test/main.go → go/tests/prog/chunk_test/main.go

0
go/tests/func/collatzcountdown_test/main.go → go/tests/prog/collatzcountdown_test/main.go

0
go/tests/func/compact_test/main.go → go/tests/prog/compact_test/main.go

0
go/tests/func/compare_test/main.go → go/tests/prog/compare_test/main.go

0
go/tests/func/concat_test/main.go → go/tests/prog/concat_test/main.go

0
go/tests/func/concatparams_test/main.go → go/tests/prog/concatparams_test/main.go

0
go/tests/func/convertbase_test/main.go → go/tests/prog/convertbase_test/main.go

0
go/tests/func/correct/btree.go → go/tests/prog/correct/btree.go

0
go/tests/func/correct/challenge.go → go/tests/prog/correct/challenge.go

0
go/tests/func/correct/listat.go → go/tests/prog/correct/listat.go

0
go/tests/func/correct/listclear.go → go/tests/prog/correct/listclear.go

0
go/tests/func/correct/listfind.go → go/tests/prog/correct/listfind.go

0
go/tests/func/correct/listforeach.go → go/tests/prog/correct/listforeach.go

0
go/tests/func/correct/listforeachif.go → go/tests/prog/correct/listforeachif.go

0
go/tests/func/correct/listlast.go → go/tests/prog/correct/listlast.go

0
go/tests/func/correct/listmerge.go → go/tests/prog/correct/listmerge.go

0
go/tests/func/correct/listpushback.go → go/tests/prog/correct/listpushback.go

0
go/tests/func/correct/listpushfront.go → go/tests/prog/correct/listpushfront.go

0
go/tests/func/correct/listremoveif.go → go/tests/prog/correct/listremoveif.go

0
go/tests/func/correct/listreverse.go → go/tests/prog/correct/listreverse.go

0
go/tests/func/correct/listsize.go → go/tests/prog/correct/listsize.go

0
go/tests/func/correct/listsort.go → go/tests/prog/correct/listsort.go

0
go/tests/func/correct/sortedlistmerge.go → go/tests/prog/correct/sortedlistmerge.go

0
go/tests/func/correct/sortlistinsert.go → go/tests/prog/correct/sortlistinsert.go

0
go/tests/func/countif_test/main.go → go/tests/prog/countif_test/main.go

0
go/tests/func/divmod_test/main.go → go/tests/prog/divmod_test/main.go

0
go/tests/func/doppelganger_test/main.go → go/tests/prog/doppelganger_test/main.go

0
go/tests/func/eightqueens_test/main.go → go/tests/prog/eightqueens_test/main.go

0
go/tests/func/enigma_test/main.go → go/tests/prog/enigma_test/main.go

0
go/tests/func/fib_test/main.go → go/tests/prog/fib_test/main.go

0
go/tests/func/fibonacci_test/main.go → go/tests/prog/fibonacci_test/main.go

0
go/tests/func/findnextprime_test/main.go → go/tests/prog/findnextprime_test/main.go

0
go/tests/func/findprevprime_test/main.go → go/tests/prog/findprevprime_test/main.go

0
go/tests/func/firstrune_test/main.go → go/tests/prog/firstrune_test/main.go

0
go/tests/func/foldint_test/main.go → go/tests/prog/foldint_test/main.go

0
go/tests/func/foreach_test/main.go → go/tests/prog/foreach_test/main.go

0
go/tests/func/game23_test/main.go → go/tests/prog/game23_test/main.go

0
go/tests/func/halfcontest_test/main.go → go/tests/prog/halfcontest_test/main.go

0
go/tests/func/index_test/main.go → go/tests/prog/index_test/main.go

0
go/tests/func/interestingnumber_test/main.go → go/tests/prog/interestingnumber_test/main.go

0
go/tests/func/isalpha_test/main.go → go/tests/prog/isalpha_test/main.go

0
go/tests/func/isanagram_test/main.go → go/tests/prog/isanagram_test/main.go

0
go/tests/func/islower_test/main.go → go/tests/prog/islower_test/main.go

0
go/tests/func/isnegative_test/main.go → go/tests/prog/isnegative_test/main.go

0
go/tests/func/isnumeric_test/main.go → go/tests/prog/isnumeric_test/main.go

0
go/tests/func/isprime_test/main.go → go/tests/prog/isprime_test/main.go

0
go/tests/func/isprintable_test/main.go → go/tests/prog/isprintable_test/main.go

0
go/tests/func/issorted_test/main.go → go/tests/prog/issorted_test/main.go

0
go/tests/func/isupper_test/main.go → go/tests/prog/isupper_test/main.go

0
go/tests/func/iterativefactorial_test/main.go → go/tests/prog/iterativefactorial_test/main.go

0
go/tests/func/iterativepower_test/main.go → go/tests/prog/iterativepower_test/main.go

0
go/tests/func/itoa_test/main.go → go/tests/prog/itoa_test/main.go

0
go/tests/func/itoabase_test/main.go → go/tests/prog/itoabase_test/main.go

0
go/tests/func/join_test/main.go → go/tests/prog/join_test/main.go

0
go/tests/func/lastrune_test/main.go → go/tests/prog/lastrune_test/main.go

0
go/tests/func/lcm_test/main.go → go/tests/prog/lcm_test/main.go

0
go/tests/func/listat_test/main.go → go/tests/prog/listat_test/main.go

0
go/tests/func/listclear_test/main.go → go/tests/prog/listclear_test/main.go

0
go/tests/func/listfind_test/main.go → go/tests/prog/listfind_test/main.go

0
go/tests/func/listforeach_test/main.go → go/tests/prog/listforeach_test/main.go

0
go/tests/func/listforeachif_test/main.go → go/tests/prog/listforeachif_test/main.go

0
go/tests/func/listlast_test/main.go → go/tests/prog/listlast_test/main.go

0
go/tests/func/listmerge_test/main.go → go/tests/prog/listmerge_test/main.go

0
go/tests/func/listpushback_test/main.go → go/tests/prog/listpushback_test/main.go

0
go/tests/func/listpushfront_test/main.go → go/tests/prog/listpushfront_test/main.go

0
go/tests/func/listremoveif_test/main.go → go/tests/prog/listremoveif_test/main.go

0
go/tests/func/listreverse_test/main.go → go/tests/prog/listreverse_test/main.go

0
go/tests/func/listsize_test/main.go → go/tests/prog/listsize_test/main.go

0
go/tests/func/listsort_test/main.go → go/tests/prog/listsort_test/main.go

0
go/tests/func/makerange_test/main.go → go/tests/prog/makerange_test/main.go

0
go/tests/func/map_test/main.go → go/tests/prog/map_test/main.go

0
go/tests/func/max_test/main.go → go/tests/prog/max_test/main.go

0
go/tests/func/nauuo_test/main.go → go/tests/prog/nauuo_test/main.go

Some files were not shown because too many files changed in this diff diff.show_more

Loading…
Cancel
Save