IBM-Swift/Kitura

View on GitHub
Tests/KituraTests/TestStaticFileServer.swift

Summary

Maintainability
F
5 days
Test Coverage

File TestStaticFileServer.swift has 588 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import XCTest
import Foundation

@testable import Kitura
@testable import KituraNet
Severity: Major
Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 day to fix

    TestStaticFileServer has 39 methods (exceeds 20 allowed). Consider refactoring.
    Open

    final class TestStaticFileServer: KituraTest, KituraTestSuite {
    
        static var allTests: [(String, (TestStaticFileServer) -> () throws -> Void)] {
            return [
                ("testFileServer", testFileServer),
    Severity: Minor
    Found in Tests/KituraTests/TestStaticFileServer.swift - About 5 hrs to fix

      Function testFileServer has 97 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          func testFileServer() {
              performServerTest(router, asyncTasks: { expectation in
                  self.performRequest("get", path:"/qwer", callback: {response in
                      XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                      XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
      Severity: Major
      Found in Tests/KituraTests/TestStaticFileServer.swift - About 3 hrs to fix

        Function testFileServer has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            func testFileServer() {
                performServerTest(router, asyncTasks: { expectation in
                    self.performRequest("get", path:"/qwer", callback: {response in
                        XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                        XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
        Severity: Minor
        Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 hr to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        Function testRangeRequestsWithMultipleRanges has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            func testRangeRequestsWithMultipleRanges() {
                performServerTest(router) { expectation in
                    self.performRequest("get", path: "/qwer/index.html", callback: { response in
                        defer {
                            expectation.fulfill()
        Severity: Minor
        Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 hr to fix

          Function runGetResponseTest has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              private func runGetResponseTest(path: String, expectedResponseText: String? = nil,
                                              expectedStatusCode: HTTPStatusCode = HTTPStatusCode.OK,
                                              bodyChecker: BodyChecker? = nil,
                                              withRouter: Router? = nil) {
                  performServerTest(withRouter ?? router) { expectation in
          Severity: Minor
          Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function testDataIsNotCorrupted has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              func testDataIsNotCorrupted() {
                  // Corrupted files will have more bytes or less bytes than required
                  // So we check the file is intact after reconstructing it (after various range requests)
                  performServerTest(router) { expectation in
                      self.performRequest("get", path: "/qwer/index.html", callback: { response in
          Severity: Minor
          Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function testDataIsNotCorrupted has 31 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              func testDataIsNotCorrupted() {
                  // Corrupted files will have more bytes or less bytes than required
                  // So we check the file is intact after reconstructing it (after various range requests)
                  performServerTest(router) { expectation in
                      self.performRequest("get", path: "/qwer/index.html", callback: { response in
          Severity: Minor
          Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 hr to fix

            Function assertMatch has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                func assertMatch(_ target: String?, _ pattern: String, matchedGroups: inout [String], file: StaticString = #file, line: UInt = #line) {
                    guard let regex = try? NSRegularExpression(pattern: pattern, options: [])else {
                        return XCTFail("invalid pattern: \(pattern)", file: file, line: line)
                    }
                    guard let target = target else {
            Severity: Minor
            Found in Tests/KituraTests/TestStaticFileServer.swift - About 1 hr to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function testRangeRequestsWithMultipleRanges has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                func testRangeRequestsWithMultipleRanges() {
                    performServerTest(router) { expectation in
                        self.performRequest("get", path: "/qwer/index.html", callback: { response in
                            defer {
                                expectation.fulfill()
            Severity: Minor
            Found in Tests/KituraTests/TestStaticFileServer.swift - About 55 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function assertMatch has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                func assertMatch(_ target: String?, _ pattern: String, matchedGroups: inout [String], file: StaticString = #file, line: UInt = #line) {
            Severity: Minor
            Found in Tests/KituraTests/TestStaticFileServer.swift - About 35 mins to fix

              Function runGetResponseTest has 5 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                  private func runGetResponseTest(path: String, expectedResponseText: String? = nil,
                                                  expectedStatusCode: HTTPStatusCode = HTTPStatusCode.OK,
                                                  bodyChecker: BodyChecker? = nil,
                                                  withRouter: Router? = nil) {
              Severity: Minor
              Found in Tests/KituraTests/TestStaticFileServer.swift - About 35 mins to fix

                Function testStaticFileServerRedirectPreservingQueryParams has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                    func testStaticFileServerRedirectPreservingQueryParams() {
                        performServerTest(router) { expectation in
                            self.performRequest("get", path: "/queryparams?a=b&c=d", followRedirects: false, callback: { response in
                                defer {
                                    expectation.fulfill()
                Severity: Minor
                Found in Tests/KituraTests/TestStaticFileServer.swift - About 25 mins to fix

                Cognitive Complexity

                Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                A method's cognitive complexity is based on a few simple rules:

                • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                • Code is considered more complex for each "break in the linear flow of the code"
                • Code is considered more complex when "flow breaking structures are nested"

                Further reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                /**
                 * Copyright IBM Corporation 2016,2017
                 *
                 * Licensed under the Apache License, Version 2.0 (the "License");
                 * you may not use this file except in compliance with the License.
                Severity: Major
                Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 2 hrs to fix
                Tests/KituraTests/TestStaticFileServer.swift on lines 1..710

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 174.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                                self.performRequest("get", path: "/qwer/index.html", callback: { response in
                                    XCTAssertNotNil(response)
                                    XCTAssertEqual(response?.statusCode, HTTPStatusCode.partialContent)
                                    XCTAssertEqual(response?.headers["Content-Range"]?.first, "bytes 0-10/\(self.indexHtmlCount)")
                                    var data = Data()
                Severity: Major
                Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestStaticFileServer.swift on lines 603..610

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 116.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                                self.performRequest("get", path: "/qwer/index.html", callback: { response in
                                    XCTAssertNotNil(response)
                                    XCTAssertEqual(response?.statusCode, HTTPStatusCode.partialContent)
                                    XCTAssertEqual(response?.headers["Content-Range"]?.first, "bytes 0-10/\(self.indexHtmlCount)")
                                    var data = Data()
                Severity: Major
                Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestStaticFileServer.swift on lines 565..572

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 116.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        performServerTest(router, asyncTasks: { expectation in
                            self.performRequest("get", path:"/help/contact", callback: { response in
                                XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                                XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                                do {
                Severity: Major
                Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestStaticFileServer.swift on lines 687..699

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 106.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                        performServerTest(router, asyncTasks: { expectation in
                            self.performRequest("get", path:"/help/contact/details", callback: { response in
                                XCTAssertNotNil(response, "ERROR!!! ClientRequest response object was nil")
                                XCTAssertEqual(response?.statusCode, HTTPStatusCode.OK, "HTTP Status code was \(String(describing: response?.statusCode))")
                                do {
                Severity: Major
                Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestStaticFileServer.swift on lines 654..666

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 106.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    func testRangeRequestWithIfRangeHeaderWithOldETag() {
                        performServerTest(router) { expectation in
                            // if ETag is NOT the same then the entire file (200) should be served
                            self.performRequest("get", path: "/qwer/index.html", callback: { response in
                                XCTAssertNotNil(response)
                Severity: Major
                Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestStaticFileServer.swift on lines 616..627

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 99.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                Similar blocks of code found in 2 locations. Consider refactoring.
                Open

                    func testRangeRequestWithIfRangeHeaderAsOldLastModified() {
                        // Range request with If-Range with etag
                        performServerTest(router) { expectation in
                            // if Last-Modified is NOT the same then the entire file (200) should be served
                            self.performRequest("get", path: "/qwer/index.html", callback: { response in
                Severity: Major
                Found in Tests/KituraTests/TestStaticFileServer.swift and 1 other location - About 1 hr to fix
                Tests/KituraTests/TestStaticFileServer.swift on lines 578..589

                Duplicated Code

                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                Tuning

                This issue has a mass of 99.

                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                Refactorings

                Further Reading

                There are no issues that match your filters.

                Category
                Status