Skip to content

Commit

Permalink
Merged Pull Request '#49 feat/with_properties->main : improved engine…
Browse files Browse the repository at this point in the history
… options, WithProperties, WithConfigHash provided'

improved engine options, WithProperties, WithConfigHash provided
  • Loading branch information
Automation51D authored May 22, 2024
2 parents 142d9c5 + d1e7c74 commit 2dae884
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 84 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea
assets
51Degrees-LiteV4.1.hash
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ go env -w CGO_ENABLED=1

This module name `device-detection-go` at path `github.com/51Degrees/device-detection-go/v4`

This Go Lite version contains only one single package:
- `dd`
This Go Lite version contains the following packages:
- `dd` - a lower level API wrapping the C device detection library
- `onpremise` - a higher level Engine API providing device detection and [automatic data file updates](https://51degrees.com/documentation/4.4/_features__automatic_datafile_updates.html)

## Build and Usage

Expand All @@ -77,12 +78,12 @@ The amalgamation is produced automatically and regularly by the [Nightly Package

## Test

Unit tests can be run with `go test` within `dd` directory.
Unit tests can be run with `go test ./...` from the root dir.

## APIs

To view APIs and their descriptions, users can use `go doc` in the package directory.
- First navigate to folder `dd`.
- First navigate to `dd` or `onpremise` dir.
- Then run the below to display all APIs, structures and their descriptions.
```
go doc -all
Expand Down
12 changes: 0 additions & 12 deletions onpremise/file_pulling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,13 @@ func newMockUncompressedDataFileServer(timeout time.Duration) *httptest.Server {
func TestFilePulling(t *testing.T) {
server := newMockDataFileServer(10 * time.Second)
defer server.Close()

config := dd.NewConfigHash(dd.Balanced)

tempFile, err := unzipAndSaveToTempFile("test_file_pulling_test.hash")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
}
defer os.Remove(tempFile.Name())

engine, err := New(
config,
WithDataUpdateUrl(
server.URL+"/datafile",
),
Expand Down Expand Up @@ -266,8 +262,6 @@ func TestIsUpdateOnStartDisabled(t *testing.T) {
server := newMockDataFileServer(10 * time.Second)
defer server.Close()

config := dd.NewConfigHash(dd.Balanced)

tempFile, err := unzipAndSaveToTempFile("TestIsUpdateOnStartDisabled.hash")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
Expand All @@ -276,7 +270,6 @@ func TestIsUpdateOnStartDisabled(t *testing.T) {
defer os.Remove(tempFile.Name())

engine, err := New(
config,
WithDataUpdateUrl(
server.URL+"/datafile",
),
Expand All @@ -302,8 +295,6 @@ func TestToggleAutoUpdate(t *testing.T) {
server := newMockDataFileServer(10 * time.Second)
defer server.Close()

config := dd.NewConfigHash(dd.Balanced)

tempFile, err := unzipAndSaveToTempFile("TestToggleAutoUpdate.hash")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
Expand All @@ -312,7 +303,6 @@ func TestToggleAutoUpdate(t *testing.T) {
defer os.Remove(tempFile.Name())

engine, err := New(
config,
WithDataUpdateUrl(
server.URL+"/datafile",
),
Expand All @@ -339,7 +329,6 @@ func TestUncompressedDataUrl(t *testing.T) {
server := newMockUncompressedDataFileServer(10 * time.Second)
defer server.Close()

config := dd.NewConfigHash(dd.Balanced)
tempFile, err := unzipAndSaveToTempFile("TestUncompressedDataUrl.hash")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
Expand All @@ -348,7 +337,6 @@ func TestUncompressedDataUrl(t *testing.T) {
defer os.Remove(tempFile.Name())

engine, err := New(
config,
WithDataUpdateUrl(server.URL+"/datafile"),
WithPollingInterval(2),
WithDataFile(tempFile.Name()),
Expand Down
5 changes: 0 additions & 5 deletions onpremise/file_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ func unzipAndSaveToTempFile(name string) (*os.File, error) {
}

func TestExternalFileChangedReplace(t *testing.T) {
config := dd.NewConfigHash(dd.Balanced)

tempFile, err := unzipAndSaveToTempFile("TestExternalFileChangedReplace.hash")
if err != nil {
t.Fatalf("Error creating temp file: %v", err)
Expand All @@ -53,7 +51,6 @@ func TestExternalFileChangedReplace(t *testing.T) {
defer tempFile.Close()

engine, err := New(
config,
WithDataFile("TestExternalFileChangedReplace.hash"),
WithFileWatch(true),
WithAutoUpdate(false),
Expand Down Expand Up @@ -154,7 +151,6 @@ func TestExternalFileChangedMv(t *testing.T) {
if runtime.GOOS == "windows" {
return
}
config := dd.NewConfigHash(dd.Balanced)

tempDir, err := os.MkdirTemp("", "TestExternalFileChangedMv")
if err != nil {
Expand All @@ -169,7 +165,6 @@ func TestExternalFileChangedMv(t *testing.T) {
defer tempFile.Close()

engine, err := New(
config,
WithDataFile(originalFileName),
WithFileWatch(true),
WithAutoUpdate(false),
Expand Down
Loading

0 comments on commit 2dae884

Please sign in to comment.