Skip to content
Permalink
Browse files
add test & doc for authentication (#5)
  • Loading branch information
houqp committed Sep 6, 2020
1 parent 781c285 commit e1deffdac6529e02da148888d530ba3099644187
Showing 4 changed files with 96 additions and 4 deletions.
@@ -39,15 +39,23 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go_version: [1.13, 1.14, 1.15]
steps:
- name: Checkout
uses: actions/checkout@master

- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.14
go-version: ${{ matrix.go_version }}
id: go

- name: build & test
run: cd airflow && go test
- name: Run tests
run: |
go test
- name: Run auto generated tests
run: |
cd airflow && go test
@@ -37,7 +37,13 @@ func main() {
Host: "localhost:28080",
BasePath: "/api/v1",
})
ctx := context.TODO()
cred := airflow.BasicAuth{
UserName: "username",
Password: "password",
}
ctx := context.WithValue(context.Background(), airflow.ContextBasicAuth, cred)
variable, _, err := client.VariableApi.GetVariable(ctx, "foo")
if err != nil {
fmt.Println(variable)
@@ -0,0 +1,70 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package client_test

import (
"context"
"encoding/base64"
"fmt"
"net/http"
"net/http/httptest"
"net/url"
"testing"

"github.com/apache/airflow-client-go/airflow"
"github.com/stretchr/testify/assert"
)

func TestBasicAuth(t *testing.T) {
// Start a local HTTP server
server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
assert.Equal(
t,
fmt.Sprintf(
"Basic %s",
base64.StdEncoding.EncodeToString([]byte("username:password")),
),
req.Header.Get("Authorization"))
assert.Equal(t, "/api/v1/variables/foo", req.URL.String())
rw.Header().Set("Content-Type", "application/json")
rw.Write([]byte(`{"key": "foo", "value": "bar"}`))
}))
// Close the server when test finishes
defer server.Close()
url, err := url.Parse(server.URL)
assert.Equal(t, nil, err)

cli := airflow.NewAPIClient(&airflow.Configuration{
Scheme: "http",
Host: url.Host,
BasePath: "/api/v1",
})

cred := airflow.BasicAuth{
UserName: "username",
Password: "password",
}
ctx := context.WithValue(context.Background(), airflow.ContextBasicAuth, cred)

variable, _, err := cli.VariableApi.GetVariable(ctx, "foo")
assert.Equal(t, nil, err)
assert.Equal(t, airflow.Variable{
Key: "foo",
Value: "bar",
}, variable)
}
8 go.mod
@@ -0,0 +1,8 @@
module github.com/apache/airflow-client-go

go 1.13

require (
github.com/apache/airflow-client-go/airflow v0.0.0-20200725194829-781c285536c1
github.com/stretchr/testify v1.6.1
)

0 comments on commit e1deffd

Please sign in to comment.