Skip to content

Commit

Permalink
Finish v0.11.1
Browse files Browse the repository at this point in the history
  • Loading branch information
proofrock committed Sep 28, 2022
2 parents 2e66f56 + 8bf318a commit b4571c0
Show file tree
Hide file tree
Showing 13 changed files with 164 additions and 20 deletions.
102 changes: 99 additions & 3 deletions .gitignore
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.vscode/
/notes

# Created by https://www.toptal.com/developers/gitignore/api/go,visualstudiocode,macos,linux
# Edit at https://www.toptal.com/developers/gitignore?templates=go,visualstudiocode,macos,linux
# Created by https://www.toptal.com/developers/gitignore/api/go,macos,linux,visualstudiocode,intellij+all
# Edit at https://www.toptal.com/developers/gitignore?templates=go,macos,linux,visualstudiocode,intellij+all

### Go ###
# If you prefer the allow list template instead of the deny list, see community template:
Expand Down Expand Up @@ -31,6 +31,94 @@ go.work
/vendor/
/Godeps/

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# AWS User-specific
.idea/**/aws.xml

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# SonarLint plugin
.idea/sonarlint/

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignore everything but code style settings and run configurations
# that are supposed to be shared within teams.

.idea/*

!.idea/codeStyles
!.idea/runConfigurations

### Linux ###
*~

Expand Down Expand Up @@ -75,6 +163,10 @@ Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
Expand All @@ -95,5 +187,9 @@ Temporary Items
.ionide

# Support for Project snippet scope
.vscode/*.code-snippets

# Ignore code-workspaces
*.code-workspace

# End of https://www.toptal.com/developers/gitignore/api/go,visualstudiocode,macos,linux
# End of https://www.toptal.com/developers/gitignore/api/go,macos,linux,visualstudiocode,intellij+all
Empty file modified LICENSE
100644 → 100755
Empty file.
4 changes: 3 additions & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ This is an implementation of a client for [ws4sqlite](https://github.com/proofro

Each client's minor release is guaranteed to be compatible with the matching minor release of ws4sqlite. So, for ws4sqlite's version `0.11.0`, use any of the client's `0.11.x` versions.

In addition, versions `0.11.x` of this package are also compatible with versions `0.12.x` of ws4sqlite.

The library requires Go 1.17 or higher.

## Import
Expand Down Expand Up @@ -61,7 +63,7 @@ if err != nil {
}

// Call ws4sqlite, obtaining a response and the status code (and a possible error)
// Status code is !=0 if the method got a response from ws4sqlite, regardless of error.
// Status code is !=0 if the method got a response from ws4sqlite, regardless of errors.
res, code, err := cli.Send(req)

// Code is 200?
Expand Down
36 changes: 22 additions & 14 deletions client.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package ws4sqlite_client

// 0.11.0
// 0.11.1

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -54,14 +55,12 @@ const (
//
// Example:
//
// cli, err := ws4.NewClientBuilder().
// WithURL("http://localhost:12321/db2").
// WithInlineAuth("myUser1", "myHotPassword").
// Build()
//
// cli.Send(...)
//
// cli, err := ws4.NewClientBuilder().
// WithURL("http://localhost:12321/db2").
// WithInlineAuth("myUser1", "myHotPassword").
// Build()
//
// cli.Send(...)
type ClientBuilder struct {
url string
authMode AuthMode
Expand All @@ -75,12 +74,12 @@ type ClientBuilder struct {
//
// Example:
//
// cli, err := ws4.NewClientBuilder().
// WithURL("http://localhost:12321/db2").
// WithInlineAuth("myUser1", "myHotPassword").
// Build()
// cli, err := ws4.NewClientBuilder().
// WithURL("http://localhost:12321/db2").
// WithInlineAuth("myUser1", "myHotPassword").
// Build()
//
// cli.Send(...)
// cli.Send(...)
type Client struct {
ClientBuilder
}
Expand Down Expand Up @@ -144,6 +143,15 @@ func (cb *ClientBuilder) Build() (*Client, error) {
// Returns a WsError if the remote service returns a processing error. If the
// communication fails, it returns the "naked" error, so check for cast-ability.
func (c *Client) Send(req *Request) (*Response, int, error) {
return c.SendWithContext(context.Background(), req)
}

// SendWithContext sends a set of requests to the remote with context, wrapped in a Request.
// Returns a matching set of responses, wrapped in a Response struct.
//
// Returns a WsError if the remote service returns a processing error. If the
// communication fails, it returns the "naked" error, so check for cast-ability.
func (c *Client) SendWithContext(ctx context.Context, req *Request) (*Response, int, error) {
if c.authMode == AUTH_MODE_INLINE {
req.req.Credentials = &credentials{
User: c.user,
Expand All @@ -157,7 +165,7 @@ func (c *Client) Send(req *Request) (*Response, int, error) {
}

client := &http.Client{}
post, err := http.NewRequest("POST", c.url, bytes.NewBuffer(jsonData))
post, err := http.NewRequestWithContext(ctx, "POST", c.url, bytes.NewBuffer(jsonData))
if err != nil {
return nil, 0, err
}
Expand Down
Empty file modified errors.go
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion go.mod
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/proofrock/ws4sqlite-client-go

go 1.17
go 1.19
Empty file modified request.go
100644 → 100755
Empty file.
Empty file modified response.go
100644 → 100755
Empty file.
Empty file modified test/mydb.yaml
100644 → 100755
Empty file.
Empty file modified test/mydb2.yaml
100644 → 100755
Empty file.
Binary file removed test/ws4sqlite-0.11.0
Binary file not shown.
Binary file renamed test/ws4sqlite → test/ws4sqlite-0.12.2
Binary file not shown.
40 changes: 39 additions & 1 deletion ws4sqlite_client_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package ws4sqlite_client_test

import (
"context"
"errors"
"os"
"os/exec"
"syscall"
Expand All @@ -34,7 +36,7 @@ func kill(cmd *exec.Cmd) {
}

func TestMain(m *testing.M) {
cmd := exec.Command("test/ws4sqlite-0.11.0", "--mem-db", "mydb:test/mydb.yaml", "--mem-db", "mydb2:test/mydb2.yaml")
cmd := exec.Command("test/ws4sqlite-0.12.2", "--mem-db", "mydb:test/mydb.yaml", "--mem-db", "mydb2:test/mydb2.yaml")

err := cmd.Start()
if err != nil {
Expand Down Expand Up @@ -244,3 +246,39 @@ func TestError(t *testing.T) {
t.Error("error is not 500")
}
}

func TestCancel(t *testing.T) {
client, err := ws4.NewClientBuilder().
WithURLComponents(ws4.PROTOCOL_HTTP, "localhost", 12321, "mydb2").
WithInlineAuth("myUser1", "myHotPassword").
Build()

if err != nil {
t.Error(err)
}

request, err := ws4.NewRequestBuilder().
AddQuery("SELENCT * FROM TEMP").
Build()

if err != nil {
t.Error(err)
}

ctx, cancel := context.WithCancel(context.Background())
cancel()

_, code, err := client.SendWithContext(ctx, request)

if err == nil {
t.Error("did not fail, but should have")
}

if code == 200 {
t.Error("did return 200, but shouldn't have")
}

if !errors.Is(err, context.Canceled) {
t.Error("err is not a Context Cancelled")
}
}

0 comments on commit b4571c0

Please sign in to comment.