-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrating Kuksa Go Client from kuksa.val
- Loading branch information
Showing
21 changed files
with
2,702 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# /******************************************************************************** | ||
# * Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
# * | ||
# * See the NOTICE file(s) distributed with this work for additional | ||
# * information regarding copyright ownership. | ||
# * | ||
# * This program and the accompanying materials are made available under the | ||
# * terms of the Apache License 2.0 which is available at | ||
# * http://www.apache.org/licenses/LICENSE-2.0 | ||
# * | ||
# * SPDX-License-Identifier: Apache-2.0 | ||
# ********************************************************************************/ | ||
|
||
name: kuksa_go_client | ||
|
||
on: | ||
push: | ||
pull_request: | ||
paths: | ||
- ".github/workflows/kuksa_go_client.yaml" | ||
- "kuksa_go_client/**" | ||
workflow_dispatch: | ||
|
||
concurrency: | ||
group: ${{ github.ref }}-${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
|
||
kuksa-go-client-test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout kuksa-incubation | ||
uses: actions/checkout@v4 | ||
- name: Run go tests | ||
run: | | ||
cd kuksa_go_client | ||
# We cannot use sudo apt install protobuf-compiler | ||
# as default in Ubuntu 22.04 (3.12) consider optional as experimental feature | ||
go run protocInstall/protocInstall.go | ||
export PATH=$PATH:$HOME/protoc/bin | ||
sudo chmod +x $HOME/protoc/bin/protoc | ||
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | ||
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | ||
export PATH=$PATH:$HOME/go/bin | ||
go generate . | ||
go test . | ||
- name: golangci-lint | ||
uses: golangci/golangci-lint-action@v3 | ||
with: | ||
version: latest | ||
working-directory: kuksa_go_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kuksa_go_client | ||
.vscode | ||
*.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
# Running the KUKSA golang Client | ||
|
||
## Execute the example | ||
|
||
### Set everything up for the KUKSA.val GO client | ||
- If you do not have GO installed follow this [page](https://go.dev/doc/install) and install v1.18 or above | ||
- If you do not have a protobuf compiler installed execute the following from this directory: | ||
``` | ||
> go run protocInstall/protocInstall.go | ||
``` | ||
Or install the protobuf compiler yourself(https://grpc.io/docs/protoc-installation/) | ||
- Add the protobuf compiler (e.g. HOME_DIR/protoc/bin) to your PATH variable. For example for linux do: | ||
``` | ||
> export PATH=$PATH:$HOME/protoc/bin | ||
``` | ||
|
||
If using a newer Linux version that has protoc >= 3.19 by default you may alternatively install the protobuf compiler with apt: | ||
|
||
``` | ||
> sudo apt install protobuf-compiler | ||
``` | ||
|
||
if you use `apt`you must manually create a folder called `proto` | ||
|
||
|
||
``` | ||
> mkdir proto | ||
``` | ||
|
||
- Run the following command to install the needed GO protocol buffers plugins: | ||
``` | ||
> go install google.golang.org/protobuf/cmd/protoc-gen-go@latest | ||
> go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest | ||
``` | ||
The plugins will be installed in $GOBIN, defaulting to $GOPATH/bin which is default HOME_DIR/go/bin. It must be in your $PATH for the protocol compiler protoc to find it. | ||
For linux execute: | ||
``` | ||
> export PATH=$PATH:$HOME/go/bin | ||
``` | ||
- Then execute | ||
``` | ||
> go generate . | ||
``` | ||
if you encounter a problem, you have to give the protoc executable the right to be executed e.g in Linux run | ||
``` | ||
> sudo chmod +x <HOME_DIR>/protoc/bin/protoc | ||
``` | ||
### Run the KUKSA.val GO client | ||
#### Start KUKSA.val Server or Databroker | ||
- Build kuksa.val and start the server | ||
``` | ||
> cd kuksa.val/kuksa-val-server/build/src/ | ||
> ./kuksa-val-server | ||
``` | ||
- Alternatively, start the appropriate docker container. | ||
``` | ||
> docker run -it --rm --net=host -p 127.0.0.1:8090:8090 -e LOG_LEVEL=ALL ghcr.io/eclipse/kuksa.val/kuksa-val:master | ||
``` | ||
- Build and run KUKSA.val Databroker by executing: | ||
``` | ||
> cargo run --bin databroker | ||
``` | ||
- Alternatively, start the apropriate docker container. | ||
``` | ||
> docker run -it --rm --net=host ghcr.io/eclipse/kuksa.val/databroker:master | ||
``` | ||
- To run the GO Client execute: | ||
``` | ||
> go build . | ||
> go run . | ||
``` | ||
- Alternatively, execute: | ||
``` | ||
> ./kuksa_go_client | ||
``` | ||
|
||
### Configuration of the KUKSA.val GO client | ||
The GO clients reads the configuration file `kuksa-client.json`. In this repository example configurations for both | ||
KUKSA.val Databroker (`kuksa-client-grpc.json`) and KUKSA.val Server (`kuksa-client-ws.json`) exists. | ||
The file `kuksa-client.json` is by default linked to `kuksa-client-grpc.json`. | ||
|
||
For using the GO client with the kuksa.val server set protocol = ws and for a connection to kuksa.val Databroker set protocol = grpc. On the command line it's available through -protocol ws/grpc. | ||
|
||
*Note: For communication with KUKSA Databroker only insecure mode is supported, TLS can not be used!* | ||
|
||
### Dependency updates | ||
|
||
If dependencies needs to be updated the following commands can be used: | ||
|
||
``` | ||
go generate . | ||
go get -u | ||
go mod tidy | ||
``` | ||
|
||
This will update `go.mod`and `go.sum`. | ||
|
||
## Linters | ||
|
||
Our Continuous Integration verifies that the code pass the [Golang Linter](https://golangci-lint.run/usage/install). | ||
To avoid failing PR builds it is recommended to run the linter manually before creating a Pull Request. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,201 @@ | ||
//******************************************************************************** | ||
// Copyright (c) 2022 Contributors to the Eclipse Foundation | ||
// | ||
// See the NOTICE file(s) distributed with this work for additional | ||
// information regarding copyright ownership. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Apache License 2.0 which is available at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// ********************************************************************************/ | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/eclipse-kuksa/kuksa-incubation/kuksa_go_client/kuksa_client" | ||
"testing" | ||
) | ||
|
||
// Note: Go support two methods to write a string | ||
// | ||
// Using double quotes | ||
// var myvar := "hello \"there\"" | ||
// | ||
// Using back quotes (raw strings) | ||
// var myvar := `hello "there"` | ||
// | ||
// Single quotes only allowed for literals/runes, like 'w' | ||
|
||
func TestArrayParseNoQuote(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`[say hello, abc]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != "say hello" { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArrayParseNoInsideQuote(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`["say hello","abc"]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != "say hello" { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArrayParseNoInsideQuoteSingle(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`['say hello','abc']`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != "say hello" { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArrayParseDoubleQuote(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`["say \"hello\"","abc"]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != `say "hello"` { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArrayParseSingleQuote(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`[say \'hello\',"abc"]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != `say 'hello'` { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArrayParseComma(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`["say, hello","abc"]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != `say, hello` { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArraySquare(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`[say hello[], abc]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != `say hello[]` { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArrayEmptyStringQuoted(t *testing.T) { | ||
|
||
array, _ := kuksa_client.GetArrayFromInput[string](`["", abc]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != `` { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestArrayEmptyStringNotQuoted(t *testing.T) { | ||
// First item shall be ignored | ||
array, _ := kuksa_client.GetArrayFromInput[string](`[, abc]`) | ||
if len(array) != 1 { | ||
t.Fail() | ||
} | ||
if array[0] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestDoubleComma(t *testing.T) { | ||
// In this case the middle item is ignored | ||
array, _ := kuksa_client.GetArrayFromInput[string](`[def,, abc]`) | ||
if len(array) != 2 { | ||
t.Fail() | ||
} | ||
if array[0] != "def" { | ||
t.Fail() | ||
} | ||
if array[1] != "abc" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestQuotesInStringValues(t *testing.T) { | ||
array, _ := kuksa_client.GetArrayFromInput[string](`["dtc1, dtc2", dtc3, \" dtc4, dtc4\"]`) | ||
if len(array) != 4 { | ||
t.Fail() | ||
} | ||
if array[0] != "dtc1, dtc2" { | ||
t.Fail() | ||
} | ||
if array[1] != "dtc3" { | ||
t.Fail() | ||
} | ||
if array[2] != "\" dtc4" { | ||
t.Fail() | ||
} | ||
if array[3] != "dtc4\"" { | ||
t.Fail() | ||
} | ||
} | ||
|
||
func TestQuotesInStringValues2(t *testing.T) { | ||
array, _ := kuksa_client.GetArrayFromInput[string]("['dtc1, dtc2', dtc3, \" dtc4, dtc4\"]") | ||
if len(array) != 3 { | ||
t.Fail() | ||
} | ||
if array[0] != "dtc1, dtc2" { | ||
t.Fail() | ||
} | ||
if array[1] != "dtc3" { | ||
t.Fail() | ||
} | ||
if array[2] != " dtc4, dtc4" { | ||
t.Fail() | ||
} | ||
} |
Oops, something went wrong.